package com.jishuo.nontax.web.bill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.PaySpecialVO;
import com.jishuo.nontax.bfc.service.SpecialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @auther dinggaofei
 * @Date 2023/3/2 15:24
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/special", name = "化解专户")
@UserAuthority(menu={"bill/special","sys/basedata/basedata"})
public class SpecialController {
    @Resource
    private SpecialService specialService;
    @Resource
    private UserService userService;
    private String prefix = "bill/";

    @ResponseBody
    @RequestMapping(value = "listSpecial", name = "专户列表")
    public GridResult<PaySpecialVO> listSpecial(PaySpecialVO paySpecialVO, Pagination pagination) {
        return new GridResult<>(specialService.listSpecial(paySpecialVO, pagination));
    }

    @RequestMapping(value = {"special"}, name = "专户首页")
    public String index() {
        return prefix + "special";
    }

    @ResponseBody
    @RequestMapping(value = "sendSpecial" ,name = "发送划解专户信息")
    public  BaseResult sendSpeical(String billids , String userpwd, String usercode, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return  specialService.sendSpecial(billids);
    }

    @ResponseBody
    @RequestMapping(value = "cleanSpecial",name = "冲销化解专户信息")
    public BaseResult cleanSpecial(String billids , String userpwd, String usercode, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return  specialService.cleanSpecial(billids, usercode);
    }

    @ResponseBody
    @RequestMapping(value = "specialExport",name = "导出划解专户信息")
    public void specialExport(long bankid, String paybankdt, HttpServletResponse response){
          specialService.specialExport(bankid, paybankdt, response);
    }

}

